package com.distribute.framework.model;

import com.distribute.framework.core.web.helper.Utils;
import java.lang.reflect.Field;
import java.util.Date; 
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import javax.annotation.Resource;

import com.distribute.framework.core.web.util.Page;
import com.distribute.framework.core.lang.*; 
import com.distribute.framework.core.web.helper.WebHelper.LzMap;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.util.IbatisMap;
import com.distribute.framework.config.*;
import com.distribute.framework.plugin.*;

@namespace("configurator/property")
public @caption("系统属性") @database(DatabaseNames.distribute_sys) @source("distribute_sys") @table("srv_property") class SrvProperty implements java.io.Serializable
{
	private static final long serialVersionUID = 1l;
	private @caption("编号") @column("sp_id")    @primary  @notnull  @note("  ") Long spId;// 主键 非空     
	private @caption("名称") @column("sp_name")     @notnull  @note("  属性名称，如html中select的option的text内容") String spName;// 非空  属性名称，如html中select的option的text内容   
	private @caption("类型") @column("sp_parent")   @hidden   @notnull  @relate("$spParent") @RelateClass(SrvProperty.class)  @note("  ") Long spParent;// 非空     
 	private transient SrvProperty $spParent;//关联对象[系统属性]
	private @caption("标识") @column("sp_flag")      @note("  程序变量命名规则格式") String spFlag;//  程序变量命名规则格式   
	private @caption("数值") @column("sp_number")      @note("  ") Long spNumber;//     
	private @caption("串值") @column("sp_value")      @note("  ") String spValue;//     
	private @caption("文本") @column("sp_text") @like     @note("  ") String spText;//     
	private @caption("状态") @column("sp_status")     @notnull  @note(" 1:有效 0:内容  ") Short spStatus;// 非空 1:有效 0:内容     
	 
	//默认构造函数
	public SrvProperty(){ 
	
	}
	
	//主键构造函数
	public SrvProperty(Long id){
		this.spId = id;
	}
	
	/**所有字段构造函数 
	 SrvProperty(
	 	Utils.getString("spName")//名称 [非空]
	 	,Utils.getLong("spParent")//类型 [非空]
	 	,Utils.getString("spFlag")//标识
	 	,Utils.getLong("spNumber")//数值
	 	,Utils.getString("spValue")//串值
	 	,Utils.getString("spText")//文本
	 	,Utils.getShort("spStatus")//状态 [非空]
	 )
	**/
	public SrvProperty(String spName,Long spParent,String spFlag,Long spNumber,String spValue,String spText,Short spStatus){
		this.spName=spName;
		this.spParent=spParent;
		this.spFlag=spFlag;
		this.spNumber=spNumber;
		this.spValue=spValue;
		this.spText=spText;
		this.spStatus=spStatus;
	}
	
	//设置非空字段
	public SrvProperty setNotNull(String spName,Long spParent,Short spStatus){
		this.spName=spName;
		this.spParent=spParent;
		this.spStatus=spStatus;
		return this;
	}
	/** 编号 [非空]       **/
	public SrvProperty spId(Long spId){
		this.spId = spId;
		this.setSeted(F.spId);
		return this;
	}
	/** 名称 [非空]    属性名称，如html中select的option的text内容   **/
	public SrvProperty spName(String spName){
		this.spName = spName;
		this.setSeted(F.spName);
		return this;
	}
	/** 类型 [非空] [SrvProperty]      **/
	public SrvProperty spParent(Long spParent){
		this.spParent = spParent;
		this.setSeted(F.spParent);
		return this;
	}
	/** 标识     程序变量命名规则格式   **/
	public SrvProperty spFlag(String spFlag){
		this.spFlag = spFlag;
		this.setSeted(F.spFlag);
		return this;
	}
	/** 数值        **/
	public SrvProperty spNumber(Long spNumber){
		this.spNumber = spNumber;
		this.setSeted(F.spNumber);
		return this;
	}
	/** 串值        **/
	public SrvProperty spValue(String spValue){
		this.spValue = spValue;
		this.setSeted(F.spValue);
		return this;
	}
	/** 文本        **/
	public SrvProperty spText(String spText){
		this.spText = spText;
		this.setSeted(F.spText);
		return this;
	}
	/** 状态 [非空]   1:有效 0:内容     **/
	public SrvProperty spStatus(Short spStatus){
		this.spStatus = spStatus;
		this.setSeted(F.spStatus);
		return this;
	}
	
	
	/**
	* 克隆对象
	**/
	public SrvProperty clone(){
		SrvProperty clone = new SrvProperty();
		clone.spName=this.spName;
		clone.spParent=this.spParent;
		clone.spFlag=this.spFlag;
		clone.spNumber=this.spNumber;
		clone.spValue=this.spValue;
		clone.spText=this.spText;
		clone.spStatus=this.spStatus;
		return clone;
	}
	/**
	* 清除缓存
	**/
	public void clear(){
		Cache.clearObject(SrvProperty.M.class);
		Cache.clearValue(SrvProperty.M.class);
		Cache.deleteObject(SrvProperty.class, this.getId());
	}
	
	/**
	* 清除缓存
	**/
	public static void clear(Long id){
		Cache.clearObject(SrvProperty.M.class);
		Cache.clearValue(SrvProperty.M.class);
		Cache.deleteObject(SrvProperty.class, id);
	}
	
	
	/**
	 * 根据ID取系统属性
	 * @param id
	 * @return
	 */
	public static @api SrvProperty get(Long id){		
		return getSrvPropertyById(id);
	}
	/**
	 * 设置ID
	 * @param id
	 * @return
	 */
	public void setId(Long id){		
		this.spId = id;
	}
	
	/**
	 * 获取所有系统属性
	 * @return
	 */
	public static @api List<SrvProperty> list(Map params,Integer size){
		return getSrvPropertyList(params,size);
	}
	/**
	 * 获取系统属性分页
	 * @return
	 */
	public static @api Page<SrvProperty> page(Integer page,Integer size,Map params){
		return getSrvPropertyPage(page, size , params);
	}
	
	
	/**
	 * 根据查询条件取系统属性
	 * @param params
	 * @return
	 */
	public static @api SrvProperty Get(Map params){
		return getSrvProperty(params);
	}
	/**
	 * 获取系统属性数
	 * @return
	 */
	public static @api Long count(Map params){
		return getSrvPropertyCount(params);
	}
	/**
	 * 获取系统属性数
	 * @return
	 */
	public static @api <T> T eval(String eval,Map params){
		return getSrvPropertyEval(eval,params);
	}
	/**
	 * 获取系统属性图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey){
		return getSrvPropertyStats(params,sumKey,groupKey,-1);
	}
	/**
	 * 获取系统属性图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey,int dateType){
		return getSrvPropertyStats(params,sumKey,groupKey,dateType);
	}
	
	/**
	 * 根据ID取系统属性
	 * @param id
	 * @return
	 */
	public static @api SrvProperty getSrvPropertyById(Long id){		
		return getSrvPropertyDao().getSrvPropertyById(id);
	}
	/**
	 * 获取id
	 * @return
	 */
	public Long getId(){
		return this.spId;
	}
	
	
	/**
	 * 根据ID取系统属性的标识键值
	 * @param id
	 * @return
	 */
	public static @api String getKeyValue(Object key){
		Long id = Utils.parseLong(key);	
		if(id==null || id.longValue()==0 ){
			return "[无]";
		}
		String value = null;
		value = Cache.getValue(SrvProperty.class, id);
		if(value==null){
			SrvProperty srvProperty = get(id);
			if(srvProperty!=null){
				String strValue = srvProperty.getSpName$();
				if(!"SpName".equals("SpName"))
					strValue+="("+srvProperty.getSpName$()+")";
				Cache.setValue(SrvProperty.class, id ,strValue);
				value = strValue;
			}else{
				Cache.setValue(SrvProperty.class, id ,"{"+id+"}",30);
				value = "{"+id+"}";
			}
		}
		/************LAZY3Q_ID_KEYVALUE************/
		/************LAZY3Q_ID_KEYVALUE************/
		return value;
	}	
	
	
	/**
	 * 获取当前对象的键值
	 * @return
	 */
	public String getKeyValue(){
		/************LAZY3Q_CODE_KEYVALUE************/
		/************LAZY3Q_CODE_KEYVALUE************/
		String keyValue = this.getSpName$();
		if(!"SpName".equals("SpName"))
			keyValue+="("+this.getSpName$()+")";
		return keyValue;
	}
	
	
	/**
	 * 根据关键字精确查询系统属性对象
	 * @return
	 */
	public static @api SrvProperty find(String key){
		if(Utils.empty(key))return null;
		Map params = new HashMap();
		if(key.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
			params.put("spId", key.toLowerCase().replaceFirst("id:", ""));					
		else{//按标识查询，精确查询
			String strDefinex = "";
			strDefinex+=" or sp_name = '"+key.replaceAll("'", "''")+"'";
			strDefinex="(2=1 "+strDefinex+")";
			params.put("definex",strDefinex);
		}
		/************LAZY3Q_CODE_FIND************/
		/************LAZY3Q_CODE_FIND************/
		return SrvProperty.getSrvProperty(params);
	}
	
	
	/**
	 * 根据关键字查询系统属性
	 * @return
	 */
	public static @api List<Map> query(String key,int size,Map params,Boolean bObject){
		if(Utils.empty((String)params.get("asc")) && Utils.empty((String)params.get("desc")))//如果未传入排序字段
			params.put("desc","sp_id");//那么，默认以主键降序，传给Dao层
		String strTerm=key;		
		if(!Utils.empty(strTerm)){
			if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
				params.put("spId", strTerm.toLowerCase().replaceFirst("id:", ""));					
			else//按标识查询，模糊查询请带%
			{
				String strDefinex = "";
				strDefinex+=" or sp_name like '%"+strTerm.replaceAll("'", "''")+"%'";
				strDefinex="(2=1 "+strDefinex+")";
				params.put("definex",strDefinex);
			}
		}
		/************LAZY3Q_CODE_QUERY************/
		/************LAZY3Q_CODE_QUERY************/
			
		List<SrvProperty> list = page(0,size,params).getResult();
		
		/**
		* OK!取到数据拼成放入Map中，[{value,text,object:{...}},...]
		* value:数据ID，text:数据标识,object,整个对象
		**/
		List<Map> result = new java.util.ArrayList();
		for(SrvProperty srvProperty:list){
			Map map = new HashMap();
			map.put("key",srvProperty.getSpId().toString());
			map.put("value", Utils.js(srvProperty.getKeyValue()));
			if(bObject==true)
				map.put("object",srvProperty);
			result.add(map);
		}
		/************LAZY3Q_AFTER_QUERY************/
		/************LAZY3Q_AFTER_QUERY************/
		
		return result;
	}
	
	
	
	/**
	 * 获取所有系统属性
	 * @return
	 */
	public static @api List<SrvProperty> getSrvPropertyList(Map params,Integer size){
		return getSrvPropertyDao().getSrvPropertyList(params,0,size);
	}
	
	/**
	 * 获取系统属性分页
	 * @return
	 */
	public static @api Page<SrvProperty> getSrvPropertyPage(Integer page,Integer size,Map params){
		if(page==null)page=0;
		if(size==null)size=20;
		return getSrvPropertyDao().getSrvPropertyPage(page, size , params);
	}
	
	/**
	 * 根据查询条件取系统属性
	 * @param params
	 * @return
	 */
	public static @api SrvProperty getSrvProperty(Map params){
		return getSrvPropertyDao().getSrvProperty(params);
	}
	
	/**
	 * 保存一个系统属性
	 * @param srvProperty
	 * @return
	 */
	public static @api SrvProperty saveSrvProperty(SrvProperty srvProperty){
		return getSrvPropertyDao().saveSrvProperty(srvProperty);
	}
	
	/**
	 * 根据条件更新系统属性
	 * @param values
	 * @param params
	 */
	public static @api int updateSrvPropertyByConfirm(Map values, Map params){
		return getSrvPropertyDao().updateSrvPropertyByConfirm(values,params);
	}
	
	/**
	 * 修改一个系统属性
	 * @param srvProperty
	 * @return
	 */
	public static @api int updateSrvProperty(SrvProperty srvProperty){
		return getSrvPropertyDao().updateSrvProperty(srvProperty);
	}
	
	/**
	 * 更新系统属性非空字段
	 * @param srvProperty
	 */
	public static @api int updateSrvProperty$NotNull(SrvProperty srvProperty){
		return getSrvPropertyDao().updateSrvProperty$NotNull(srvProperty);
	}
	
	/**
	 * 获取系统属性数
	 * @return
	 */
	public static @api Long getSrvPropertyCount(Map params){
		return getSrvPropertyDao().getSrvPropertyCount(params);
	}
		
		
	/**
	 * 获取系统属性自定义求和表达式,比如求和:eval="sum(id)"
	 * @return
	 */	
	public static @api <T> T getSrvPropertyEval(String eval,Map params){
		return getSrvPropertyDao().getSrvPropertyEval(eval,params);
	}
	/**
	 * 获取系统属性图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> getSrvPropertyStats(Map params,C sumKey,C groupKey,int dateType){
		//TODO:图表统计功能未实现
		
		Map<String,Object> groups=new HashMap();//要分组的字段
		Map<String,Object> sums=new HashMap();//要统计的字段
		
		String[][] dateFormats=new String[][]{
				null,
				new String[]{"%Y","yyyy年","Y"},
				new String[]{"%Y-%m","yyyy年MM月","M"},
				new String[]{"%Y%U","yyyy年第ww周","W"},
				new String[]{"%Y-%m-%d","yyyy年MM月dd日","D"},
				new String[]{"%Y-%m-%d %H","yyyy年MM月dd日 HH点","H"},
				new String[]{"%m","MM月"},
				new String[]{"%d","dd号"},
				new String[]{"%H","HH点"} 
		};
		
		//获取要分组的字段，放入Map中
		if(dateType>0){
			groups.put(groupKey.toString(),"DATE_FORMAT({key},'"+dateFormats[dateType][0]+"')");
		}else{
			groups.put(groupKey.toString(),"{key}");
		}
		if(dateType<6 && dateType>0){ 
			params.put("asc", groupKey.toString()); 
			if(params.get(groupKey.name()+"Start")==null){
				params.put(groupKey.name()+"Start", Utils.date(new Date(), -24, dateFormats[dateType][2]));
			}
		}
		
		
		//获取要统计的字段，放入Map中
		if(sumKey.toString().equals("count")){
			sums.put(sumKey.toString(),"count(*)");
		}else{
			sums.put(sumKey.toString(),"sum({key})");
		}
		
		List<Map> list = getSrvPropertyDao().getSrvPropertyStats(params,groups,sums);
		
		List<Map> result = new ArrayList();
		for(Map m:list){
			Map map = new HashMap();
			Object value = m.get(sumKey.toString());
			Object name = null;
			Object groupValue = m.get(groupKey.toString());
			if(dateType>0){
				name = Utils.date(Utils.parseDate(groupValue), dateFormats[dateType][1]);
			}else{
				try{
					java.lang.reflect.Method method = SrvProperty.class.getMethod("get"+Utils.ForMat(groupKey.toString())+"$");
					method.setAccessible(true);
					name = method.invoke(SrvProperty.fromMap(m));
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
			map.put("name", name);
			map.put("value", value);
			result.add(map);
		}
		return result;
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static int updateSrvProperty(Map set,Map where){
		if(set.isEmpty())throw new RuntimeException("set为空");
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		return getSrvPropertyDao().updateSrvPropertyByConfirm(set, where);
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void deleteSrvProperty(Map where){
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		getSrvPropertyDao().deleteSrvPropertyByConfirm(where);
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void delete(Long id){
		if(id==null)throw new RuntimeException("id为空");
		getSrvPropertyDao().deleteSrvPropertyById(id);
	}
	
	
	/**
	 * 保存系统属性对象
	 * @param params
	 * @return
	 */
	public SrvProperty save(){
		if(this.getSpId()!=null)
			getSrvPropertyDao().updateSrvProperty(this);
		else
			return getSrvPropertyDao().saveSrvProperty(this);
		return this;
	}
	
	
	/**
	 * 更新系统属性对象的非空字段,注意跟Service里面的update不一样哦
	 * @param params
	 * @return
	 */
	public int update(){
		return getSrvPropertyDao().updateSrvProperty$NotNull(this);
	}
	
	
	/**
	 * 删除
	 * @param params
	 * @return
	 */
	public void delete(){
			getSrvPropertyDao().deleteSrvPropertyById(this.getSpId());
	}
	
	/**
	 * 执行事务
	 * @param function
	 */
	public static <T> T execute(Function function){
		return getSrvPropertyDao().executeTransaction(function);
	}
	/*******************************编号**********************************/	
	/**
	* 编号 [非空]      
	**/
	public Long getSpId(){
		if(this.spId!=null){
			return this.spId;
		}
		return this.spId;
	}
	/**
	* 获取编号格式化(toString)
	**/
	public String getSpId$(){
		String strValue="";
		 strValue=Utils.string(this.getSpId());
	 	 return strValue;
	}
	/**
	* 根据编号反格式化
	**/
	public void setSpId$(String strValue){
		if(Utils.empty(strValue)){
			this.spId=null;
			return;
		}
	 	this.spId=Utils.parseLong(strValue);
	}
	
	/**
	* 编号 [非空]      
	**/
	public void setSpId(Long spId){
		this.spId = spId;
		this.setSeted(F.spId);
	}
	
	
	
	
	/*******************************名称**********************************/	
	/**
	* 名称 [非空]    属性名称，如html中select的option的text内容  
	**/
	public String getSpName(){
		if(this.spName!=null){
			return this.spName;
		}
		return this.spName;
	}
	/**
	* 获取名称格式化(toString)
	**/
	public String getSpName$(){
		String strValue="";
		 strValue=Utils.string(this.getSpName());
	 	 return strValue;
	}
	/**
	* 根据名称反格式化
	**/
	public void setSpName$(String strValue){
		if(Utils.empty(strValue)){
			this.spName=null;
			return;
		}
	 	this.spName=strValue;
	}
	
	/**
	* 名称 [非空]    属性名称，如html中select的option的text内容  
	**/
	public void setSpName(String spName){
		this.spName = spName;
		this.setSeted(F.spName);
	}
	
	
	
	
	/*******************************类型**********************************/	
	/**
	* 类型 [非空] [SrvProperty]     
	**/
	public Long getSpParent(){
		if(this.spParent!=null){
			return this.spParent;
		}
		return this.spParent;
	}
	/**
	* 获取类型格式化(toString)
	**/
	public String getSpParent$(){
		String strValue="";
		if(this.getSpParent()!=null){
				strValue+=Utils.string(SrvProperty.getKeyValue(this.getSpParent()));
		}			
	 	 return strValue;
	}
	/**
	* 根据类型反格式化
	**/
	public void setSpParent$(String strValue){
		if(Utils.empty(strValue)){
			this.spParent=null;
			return;
		}
		SrvProperty item = SrvProperty.find(strValue);
		if(item!=null){
			this.spParent = Utils.parseLong(item.getSpId());
		}
	}
	
	/**
	* 类型 [非空] [SrvProperty]     
	**/
	public void setSpParent(Long spParent){
		this.spParent = spParent;
		this.setSeted(F.spParent);
	}
	
	
	
	
	/**
	* 获取关联对象[系统属性]
	**/	 			
 	public SrvProperty get$spParent(){
 		if(this.$spParent!=null)
 			return this.$spParent;
 		com.distribute.framework.model.SrvProperty srvProperty = null;
		if(this.getSpParent()!=null){
 			srvProperty = SrvProperty.get(this.getSpParent());
 		}
 		return srvProperty;
	}
	/*******************************标识**********************************/	
	/**
	* 标识     程序变量命名规则格式  
	**/
	public String getSpFlag(){
		if(this.spFlag!=null){
			return this.spFlag;
		}
		return this.spFlag;
	}
	/**
	* 获取标识格式化(toString)
	**/
	public String getSpFlag$(){
		String strValue="";
		 strValue=Utils.string(this.getSpFlag());
	 	 return strValue;
	}
	/**
	* 根据标识反格式化
	**/
	public void setSpFlag$(String strValue){
		if(Utils.empty(strValue)){
			this.spFlag=null;
			return;
		}
	 	this.spFlag=strValue;
	}
	
	/**
	* 标识     程序变量命名规则格式  
	**/
	public void setSpFlag(String spFlag){
		this.spFlag = spFlag;
		this.setSeted(F.spFlag);
	}
	
	
	
	
	/*******************************数值**********************************/	
	/**
	* 数值       
	**/
	public Long getSpNumber(){
		if(this.spNumber!=null){
			return this.spNumber;
		}
		return this.spNumber;
	}
	/**
	* 获取数值格式化(toString)
	**/
	public String getSpNumber$(){
		String strValue="";
		 strValue=Utils.string(this.getSpNumber());
	 	 return strValue;
	}
	/**
	* 根据数值反格式化
	**/
	public void setSpNumber$(String strValue){
		if(Utils.empty(strValue)){
			this.spNumber=null;
			return;
		}
	 	this.spNumber=Utils.parseLong(strValue);
	}
	
	/**
	* 数值       
	**/
	public void setSpNumber(Long spNumber){
		this.spNumber = spNumber;
		this.setSeted(F.spNumber);
	}
	
	
	
	
	/*******************************串值**********************************/	
	/**
	* 串值       
	**/
	public String getSpValue(){
		if(this.spValue!=null){
			return this.spValue;
		}
		return this.spValue;
	}
	/**
	* 获取串值格式化(toString)
	**/
	public String getSpValue$(){
		String strValue="";
		 strValue=Utils.string(this.getSpValue());
	 	 return strValue;
	}
	/**
	* 根据串值反格式化
	**/
	public void setSpValue$(String strValue){
		if(Utils.empty(strValue)){
			this.spValue=null;
			return;
		}
	 	this.spValue=strValue;
	}
	
	/**
	* 串值       
	**/
	public void setSpValue(String spValue){
		this.spValue = spValue;
		this.setSeted(F.spValue);
	}
	
	
	
	
	/*******************************文本**********************************/	
	/**
	* 文本       
	**/
	public String getSpText(){
		if(this.spText!=null){
			return this.spText;
		}
		return this.spText;
	}
	/**
	* 获取文本格式化(toString)
	**/
	public String getSpText$(){
		String strValue="";
		 strValue=Utils.string(this.getSpText());
	 	 return strValue;
	}
	/**
	* 根据文本反格式化
	**/
	public void setSpText$(String strValue){
		if(Utils.empty(strValue)){
			this.spText=null;
			return;
		}
		this.spText=strValue;
	}
	
	/**
	* 文本       
	**/
	public void setSpText(String spText){
		this.spText = spText;
		this.setSeted(F.spText);
	}
	
	
	
	
	/*******************************状态**********************************/	
	/**
	* 状态 [非空]   1:有效 0:内容    
	**/
	public Short getSpStatus(){
		if(this.spStatus!=null){
			return this.spStatus;
		}
		return this.spStatus;
	}
	/**
	* 获取状态格式化(toString)
	**/
	public String getSpStatus$(){
		String strValue="";
		 if(Utils.equals(Utils.string(this.getSpStatus()),"1"))
			strValue=Utils.string("有效");		 
		 if(Utils.equals(Utils.string(this.getSpStatus()),"0"))
			strValue=Utils.string("内容");		 
	 	 return strValue;
	}
	/**
	* 根据状态反格式化
	**/
	public void setSpStatus$(String strValue){
		if(Utils.empty(strValue)){
			this.spStatus=null;
			return;
		}
		 if(Utils.equals(strValue,"有效"))
		 	this.spStatus=Utils.parseShort("1");
		 if(Utils.equals(strValue,"内容"))
		 	this.spStatus=Utils.parseShort("0");
	}
	
	/**
	* 状态 [非空]   1:有效 0:内容    
	**/
	public void setSpStatus(Short spStatus){
		this.spStatus = spStatus;
		this.setSeted(F.spStatus);
	}
	
	
	
	
	/************LAZY3Q_DEFINE_CODE************/
	/************LAZY3Q_DEFINE_CODE************/
	
	
	/**
	 * 触发器
	 */
	public static void on(Trigger.Index index,final Notify.Listener listener,Trigger.Type... types){
		Notify.on(SrvProperty.class, index, listener, types);
	}
	public static void on(final Notify.Listener listener,String type){
		Notify.on(SrvProperty.class, listener, type);
	}
	/**
	 * 当修改字段时
	 * @param filedName
	 * @param listener
	 */
	public static void on(String filedName,final Notify.Listener listener){
		Notify.on(SrvProperty.class, listener, filedName);
	}
	/**
	 * 当修改字段为某值时
	 * @param filedName
	 * @param value
	 * @param listener
	 */
	public static void on(String filedName,Object value,final Notify.Listener listener){
		if(value==null)return;
		Notify.on(SrvProperty.class, listener, filedName+"."+Utils.md5(""+value));
	}
	public void notify(String type){
		Trigger.on(SrvProperty.class,type, this);
	}
	
	
	/**
	 * 用来获取当有字段关联对象时的获取方式,调用如${SrvProperty.obj.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvProperty.$filedName}获取关联对象
	 */
	public Map getObj(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvProperty.class.getMethod("get$"+Utils.forMat(key.toString())).invoke(SrvProperty.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 用来获取某字段格式化的获取方式,调用如${SrvProperty.fmt.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvProperty.filedName$}获取某字段格式化
	 */
	public Map getFmt(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvProperty.class.getMethod("get"+Utils.ForMat(key.toString()+"$")).invoke(SrvProperty.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 获取查询参数链式串
	 * @return
	 */
	public static @Deprecated M where(){ return new M(0); }
	public static @Deprecated M m(){ return new M(0); }
	public static M where = new M(0,true);
	public static @database(DatabaseNames.distribute_sys) class M extends IbatisMap{
		int type = 0; 
		M linked = null;
		Boolean proxy = false;
		public M set = null;
		public M(int type){
			this.type = type;
			if(this.type==0){
				set = new M(1,true);
				set.linked = this;
			}
		};
		public M(int type,Boolean proxy){
			this.type = type;
			this.proxy=proxy;
		};
		public M proxy(){
			M m = new M(this.type);//当前的对像
			if(this.type==0){
				m.set = new M(1,true);//set对象
				m.set.linked = m;
			}else{
				m.linked=this.linked;
				this.linked.linked=m;
			}
			return m;
		}
		public @Deprecated M set(){			
			M m = this;
			m.linked=new M(1);
			m.linked.linked=m;
			return m.linked;
		};
		public M on(IbatisMap value,C column,String joinColumn){if(proxy)return proxy().on(value,column,joinColumn);this.put(value.getClass().getDeclaringClass().getSimpleName(), value);value.put("on", column.toString());value.put("to", joinColumn);return this;};
		/** 编号 [非空]       **/
		public M spId(Object spId){if(proxy)return proxy().spId(spId);  this.put("spId", spId);return this;};
	 	/** and sp_id is null */
 		public M spIdNull(){if(proxy)return proxy().spIdNull();if(this.get("spIdNot")==null)this.put("spIdNot", "");this.put("spId", null);return this;};
 		/** not .... */
 		public M spIdNot(){if(proxy)return proxy().spIdNot();this.put("spIdNot", "not");return this;};
 		public M spIdNotNull(){if(proxy)return proxy().spIdNotNull();this.put("spIdNot", "not");this.put("spId", null);return this;};
 		public M spIdNot(Object spId){if(proxy)return proxy().spIdNot(spId);this.put("spIdNot", "not");this.put("spId", spId);return this;};
		/** and sp_id <= ? */
		public M spIdMin(Object min){if(proxy)return proxy().spIdMin(min);this.put("spIdMin", min);return this;};
		/** and sp_id >= ? */
		public M spIdMax(Object max){if(proxy)return proxy().spIdMax(max);this.put("spIdMax", max);return this;};
		public M spIdIn(String ids){
			if(proxy)return proxy().spIdIn(ids);  this.put("spIdIn", ids);return this;
		};	
		/** 名称 [非空]    属性名称，如html中select的option的text内容   **/
		public M spName(Object spName){if(proxy)return proxy().spName(spName);  this.put("spName", spName);return this;};
	 	/** and sp_name is null */
 		public M spNameNull(){if(proxy)return proxy().spNameNull();if(this.get("spNameNot")==null)this.put("spNameNot", "");this.put("spName", null);return this;};
 		/** not .... */
 		public M spNameNot(){if(proxy)return proxy().spNameNot();this.put("spNameNot", "not");return this;};
 		public M spNameNotNull(){if(proxy)return proxy().spNameNotNull();this.put("spNameNot", "not");this.put("spName", null);return this;};
 		public M spNameNot(Object spName){if(proxy)return proxy().spNameNot(spName);this.put("spNameNot", "not");this.put("spName", spName);return this;};
		public M spParent$on(SrvProperty.M value){if(proxy)return proxy().spParent$on(value);this.put("SpParent", value);value.put("on", "sp_parent");return this;};
		/** 类型 [非空] [SrvProperty]      **/
		public M spParent(Object spParent){if(proxy)return proxy().spParent(spParent);  this.put("spParent", spParent);return this;};
	 	/** and sp_parent is null */
 		public M spParentNull(){if(proxy)return proxy().spParentNull();if(this.get("spParentNot")==null)this.put("spParentNot", "");this.put("spParent", null);return this;};
 		/** not .... */
 		public M spParentNot(){if(proxy)return proxy().spParentNot();this.put("spParentNot", "not");return this;};
 		public M spParentNotNull(){if(proxy)return proxy().spParentNotNull();this.put("spParentNot", "not");this.put("spParent", null);return this;};
 		public M spParentNot(Object spParent){if(proxy)return proxy().spParentNot(spParent);this.put("spParentNot", "not");this.put("spParent", spParent);return this;};
		public M spParentIn(String ids){
			if(proxy)return proxy().spParentIn(ids);  this.put("spParentIn", ids);return this;
		};	
		/** 标识     程序变量命名规则格式   **/
		public M spFlag(Object spFlag){if(proxy)return proxy().spFlag(spFlag);  this.put("spFlag", spFlag);return this;};
	 	/** and sp_flag is null */
 		public M spFlagNull(){if(proxy)return proxy().spFlagNull();if(this.get("spFlagNot")==null)this.put("spFlagNot", "");this.put("spFlag", null);return this;};
 		/** not .... */
 		public M spFlagNot(){if(proxy)return proxy().spFlagNot();this.put("spFlagNot", "not");return this;};
 		public M spFlagNotNull(){if(proxy)return proxy().spFlagNotNull();this.put("spFlagNot", "not");this.put("spFlag", null);return this;};
 		public M spFlagNot(Object spFlag){if(proxy)return proxy().spFlagNot(spFlag);this.put("spFlagNot", "not");this.put("spFlag", spFlag);return this;};
		/** 数值        **/
		public M spNumber(Object spNumber){if(proxy)return proxy().spNumber(spNumber);  this.put("spNumber", spNumber);return this;};
	 	/** and sp_number is null */
 		public M spNumberNull(){if(proxy)return proxy().spNumberNull();if(this.get("spNumberNot")==null)this.put("spNumberNot", "");this.put("spNumber", null);return this;};
 		/** not .... */
 		public M spNumberNot(){if(proxy)return proxy().spNumberNot();this.put("spNumberNot", "not");return this;};
 		public M spNumberNotNull(){if(proxy)return proxy().spNumberNotNull();this.put("spNumberNot", "not");this.put("spNumber", null);return this;};
 		public M spNumberNot(Object spNumber){if(proxy)return proxy().spNumberNot(spNumber);this.put("spNumberNot", "not");this.put("spNumber", spNumber);return this;};
		/** and sp_number <= ? */
		public M spNumberMin(Object min){if(proxy)return proxy().spNumberMin(min);this.put("spNumberMin", min);return this;};
		/** and sp_number >= ? */
		public M spNumberMax(Object max){if(proxy)return proxy().spNumberMax(max);this.put("spNumberMax", max);return this;};
		public M spNumberIn(String ids){
			if(proxy)return proxy().spNumberIn(ids);  this.put("spNumberIn", ids);return this;
		};	
		/** 串值        **/
		public M spValue(Object spValue){if(proxy)return proxy().spValue(spValue);  this.put("spValue", spValue);return this;};
	 	/** and sp_value is null */
 		public M spValueNull(){if(proxy)return proxy().spValueNull();if(this.get("spValueNot")==null)this.put("spValueNot", "");this.put("spValue", null);return this;};
 		/** not .... */
 		public M spValueNot(){if(proxy)return proxy().spValueNot();this.put("spValueNot", "not");return this;};
 		public M spValueNotNull(){if(proxy)return proxy().spValueNotNull();this.put("spValueNot", "not");this.put("spValue", null);return this;};
 		public M spValueNot(Object spValue){if(proxy)return proxy().spValueNot(spValue);this.put("spValueNot", "not");this.put("spValue", spValue);return this;};
		/** 文本        **/
		public M spText(Object spText){if(proxy)return proxy().spText(spText);  this.put("spText", spText);return this;};
	 	/** and sp_text is null */
 		public M spTextNull(){if(proxy)return proxy().spTextNull();if(this.get("spTextNot")==null)this.put("spTextNot", "");this.put("spText", null);return this;};
 		/** not .... */
 		public M spTextNot(){if(proxy)return proxy().spTextNot();this.put("spTextNot", "not");return this;};
 		public M spTextNotNull(){if(proxy)return proxy().spTextNotNull();this.put("spTextNot", "not");this.put("spText", null);return this;};
 		public M spTextNot(Object spText){if(proxy)return proxy().spTextNot(spText);this.put("spTextNot", "not");this.put("spText", spText);return this;};
		/** 状态 [非空]   1:有效 0:内容     **/
		public M spStatus(Object spStatus){if(proxy)return proxy().spStatus(spStatus);  this.put("spStatus", spStatus);return this;};
	 	/** and sp_status is null */
 		public M spStatusNull(){if(proxy)return proxy().spStatusNull();if(this.get("spStatusNot")==null)this.put("spStatusNot", "");this.put("spStatus", null);return this;};
 		/** not .... */
 		public M spStatusNot(){if(proxy)return proxy().spStatusNot();this.put("spStatusNot", "not");return this;};
 		public M spStatusNotNull(){if(proxy)return proxy().spStatusNotNull();this.put("spStatusNot", "not");this.put("spStatus", null);return this;};
 		public M spStatusNot(Object spStatus){if(proxy)return proxy().spStatusNot(spStatus);this.put("spStatusNot", "not");this.put("spStatus", spStatus);return this;};
		public M spStatusIn(String ids){
			if(proxy)return proxy().spStatusIn(ids);  this.put("spStatusIn", ids);return this;
		};	
	 	public M add(String key, Object value) {if(proxy)return proxy().add(key,value);this.put(key, value);return this;}
	 	public M add(F key, Object value) {if(proxy)return proxy().add(key,value);this.put(key.toString(), value);return this;}
	 	public M desc(C key) {if(proxy)return proxy().desc(key);this.put("desc", key.column);return this;}
	 	public M asc(C key) {if(proxy)return proxy().asc(key);this.put("asc", key.column);return this;}
	 	public M desc(String sql) {if(proxy)return proxy().desc(sql);this.put("desc", sql);return this;}
	 	public M asc(String sql) {if(proxy)return proxy().asc(sql);this.put("asc", sql);return this;}
	 	public M definex(String sql) {if(proxy)return proxy().definex(sql);this.put("definex", sql);return this;}
	 	/** 获取所有系统属性 **/
		public @api List<SrvProperty> list(Integer size){			
			return getSrvPropertyList(this,size);
		}
		/** 获取系统属性分页 **/
		public @api Page<SrvProperty> page(Integer page,Integer size){			
			return getSrvPropertyPage(page, size , this);
		}
		/** 根据查询条件取系统属性 **/
		public @api SrvProperty get(){			
			return getSrvProperty(this);
		}
		/** 获取系统属性数 **/
		public @api Long count(){			
			return getSrvPropertyCount(this);
		}
		/** 获取系统属性表达式 **/
		public @api <T> T eval(String strEval){			
			return getSrvPropertyEval(strEval,this);
		}
		/** 获取系统属性统计 **/
		public @api List<Map> stats(C sumKey,C groupKey,int dateType){			
			return getSrvPropertyStats(this,sumKey,groupKey,dateType);
		}
		/** 获取系统属性统计 **/
		public @api List<Map> stats(C sumKey,C groupKey){			
			return getSrvPropertyStats(this,sumKey,groupKey,-1);
		}
		/** 根据条件更新 **/
		public @api int update(){			
			M where = null;
			M set = null;
			if(this.type==0){
				if(this.linked==null)throw new RuntimeException("未发set");
				where = this;
				set = this.linked;
			}else{
				if(this.linked==null)throw new RuntimeException("未发where条件");
				set = this;
				where = this.linked;
			}
			return updateSrvProperty(set,where);
		}
		/** 根据条件删除 **/
		public @api void delete(){			
			deleteSrvProperty(this);
		}
	}
	
	public static class Param extends M{
		public Param(int type) {
			super(type);
		}
		public Param(int type, Boolean proxy) {
			super(type, proxy);
		}
	}
	
	/** 对象的字段描述 **/
	public static class F{
		/** 编号 [非空]       **/
		public final static @type(Long.class)  String spId="spId";
		/** 名称 [非空]    属性名称，如html中select的option的text内容   **/
		public final static @type(String.class)  String spName="spName";
		/** 类型 [非空] [SrvProperty]      **/
		public final static @type(Long.class)  String spParent="spParent";
		/** 标识     程序变量命名规则格式   **/
		public final static @type(String.class)  String spFlag="spFlag";
		/** 数值        **/
		public final static @type(Long.class)  String spNumber="spNumber";
		/** and sp_number >= ? */
		public final static @type(Long.class) String spNumberMin="spNumberMin";
		/** and sp_number <= ? */
		public final static @type(Long.class) String spNumberMax="spNumberMax";
		/** 串值        **/
		public final static @type(String.class)  String spValue="spValue";
		/** 文本        **/
		public final static @type(String.class) @like String spText="spText";
		/** 状态 [非空]   1:有效 0:内容     **/
		public final static @type(Short.class)  String spStatus="spStatus";
	 	public static String get(String name){
			try {
				Field field = F.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	/** 对象的数据库字段描述 **/
	public static enum C{
		spId("sp_id"),
		spName("sp_name"),
		spParent("sp_parent"),
		spFlag("sp_flag"),
		spNumber("sp_number"),
		spValue("sp_value"),
		spText("sp_text"),
		spStatus("sp_status"),
		count("count");
		String column;
		C(String column){
			this.column = column;
		}
		public String toString(){
			return this.column;
		}
		public static String get(String name){
			try {
				Field field = C.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	/**
	* 获取系统属性数据
	**/
	public static Object getData(Object param){
		if(param==null)
			return null;
		Object value = null;
		if(param.getClass()==Long.class)
			value = SrvProperty.get((Long)param);
		else if(param instanceof java.util.Map){
			java.util.Map params = (Map) param;
			if(params.get("size")==null)
				value = SrvProperty.getSrvProperty(params);
			else
				value = SrvProperty.getSrvPropertyList(params, (Integer) params.get("size"));
		}else if(param.getClass()==Long.class )
			value =  SrvProperty.where().spId(param).get();
		else if(!Utils.empty(param.toString()))
			value = SrvProperty.get(Long.valueOf(param.toString()));
		return value;
	}
	
	/**对象转json**/
	public Map toJSON(){
		return toJSON(false);
	}
	public Map toJSON(boolean simple){
		Map map = new HashMap();
		map.put("id",this.getSpId());
		Utils.fms(map,simple?"id":"spId",this.getSpId(),this.getSpId$());
		Utils.fms(map,simple?"name":"spName",this.getSpName(),this.getSpName$());
		Utils.fms(map,simple?"parent":"spParent",this.getSpParent(),this.getSpParent$());
		Utils.fms(map,simple?"flag":"spFlag",this.getSpFlag(),this.getSpFlag$());
		Utils.fms(map,simple?"number":"spNumber",this.getSpNumber(),this.getSpNumber$());
		Utils.fms(map,simple?"value":"spValue",this.getSpValue(),this.getSpValue$());
		Utils.fms(map,simple?"text":"spText",this.getSpText(),this.getSpText$());
		Utils.fms(map,simple?"status":"spStatus",this.getSpStatus(),this.getSpStatus$());
		if(this.suffix!=null)map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOJSON************/
		/************LAZY3Q_DEFINE_TOJSON************/
		return map;
	}
	/**对象转map**/
	public Map toMap(){
		Map map = new HashMap();
		map.put("spId",this.getSpId());
		map.put("spName",this.getSpName());
		map.put("spParent",this.getSpParent());
		map.put("spFlag",this.getSpFlag());
		map.put("spNumber",this.getSpNumber());
		map.put("spValue",this.getSpValue());
		map.put("spText",this.getSpText());
		map.put("spStatus",this.getSpStatus());
		map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOMAP************/
		/************LAZY3Q_DEFINE_TOMAP************/
		return map;
	}
	/**map转对象**/
	public static SrvProperty fromMap(Map map){
		SrvProperty srvProperty = new SrvProperty();
		srvProperty.spId = Utils.parseLong(map.get("spId"));
		srvProperty.spName = Utils.parseString(map.get("spName"));
		srvProperty.spParent = Utils.parseLong(map.get("spParent"));
		srvProperty.spFlag = Utils.parseString(map.get("spFlag"));
		srvProperty.spNumber = Utils.parseLong(map.get("spNumber"));
		srvProperty.spValue = Utils.parseString(map.get("spValue"));
		srvProperty.spText = Utils.parseString(map.get("spText"));
		srvProperty.spStatus = Utils.parseShort(map.get("spStatus"));
		return srvProperty;
	}
	
	
	
	/**字段设置标记队列**/
	private Map<String,Boolean> seted=new HashMap();
	public Boolean getSeted(String key){
		return seted.get(key);
	}
	public void setSeted(String key){
		seted.put(key,true);
	}
	/**同步未set的字段**/
	public void mergeSet(SrvProperty old){
		Field[] fields = this.getClass().getDeclaredFields();
		try {
			for(Field field:fields){
				String key = field.getName();
				if(seted.get(key)==null && field.getAnnotation(column.class)!=null){
					field.setAccessible(true);
					field.set(this, field.get(old));					
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
		
	/**自定义变量存储**/
	private Map values=new HashMap();
	public Map getValues(){
		return values;
	}
	public void setValues(String name,Object value){
		values.put(name,value);
	}
	
	/**分表时的表名后缀**/
	private String suffix;
	public String getSuffix() {
		return suffix;
	}
	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
	/**获取数据库名称**/
	public static String getDataBaseName(){
		return Utils.config("spring.datasource.distribute_sys.name");
	}
	
	public static String getIcon(){
		return "/images/icons/20088256421631277802.png";
	}
	public static String getIconfont(){
		return "icon-ziliao1";
	}
	public static enum ACT{
		列表,添加,修改,详情
	};
	public static String getUrl(ACT act,SrvProperty.M params){
		if(params==null)params=new SrvProperty.M(0);
		params.remove("joins");
		params.remove("definexs");
		params.remove("distinct");
		String strUrl = "/admin/configurator/property.edit.html?";
		if(params.get("spId")!=null){
			strUrl+="&id="+Utils.encode(""+params.get("spId"),Utils.UTF8);
		}
		if(act==ACT.列表){
			strUrl = "/admin/configurator/property.html?1=1";
		}else if(act==ACT.添加){
			strUrl+="&edittype=insert";
		}else if(act==ACT.修改){
			strUrl+="&edittype=update";
		}else if(act==ACT.详情){
			strUrl+="&edittype=detail";
		}		
		if(params!=null){
			for(Object key:params.keySet()){
				strUrl+="&"+key+"="+Utils.encode(""+params.get(key),Utils.UTF8)+"";
			}
		}
		return strUrl;
	}
	public String getDetailUrl(){
		return this.getUrl(ACT.详情, where.spId(this.getId()));
	}
	
	/**
	* 转跳到当前地址
	**/
	public static Protocol redirect(SrvProperty.ACT act,SrvProperty.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_REDIRECT");
		protocol.set("url",SrvProperty.getUrl(act, params));
		return protocol;
	}
	/**
	* 打开一个新的tab页面
	**/
	public static Protocol href(SrvProperty.ACT act,SrvProperty.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_HREF");
		protocol.set("url",SrvProperty.getUrl(act, params));
		protocol.set("title",act.name());
		return protocol;
	}
	/**
	* 显示一个消息框，并且关闭当前的对话框
	**/
	public static Protocol message(String message){
		Protocol protocol = Protocol.create(true,null,"ACT_MESSAGE");
		protocol.set("message",message);
		return protocol;
	}
	
	
	static com.distribute.framework.dao.ISrvPropertyDao getSrvPropertyDao(){
		return Utils.getBean("srvPropertyDao");
	};
	
}